window.onload = function () {

  //给图片设置自定义属性
  var cards = document.querySelectorAll('.out ul li');
  for (var i = 0; i < 13; i++) {
    cards[i].firstElementChild.setAttribute('data-index', i + 1);
  }
  console.log(cards[2].firstElementChild.getAttribute('data-index'));

  /*
    不重复的取两个数之间的值
    max取不到
  */
  function randomCommon (min, max, n) {
    if (n > (max - min + 1) || max < min) {
      return null;
    }
    var result = new Array;
    result.length = n;
    var count = 0;
    while (count < n) {
      var num = (parseInt)(Math.random() * (max - min)) + min;
      var flag = true;
      for (var j = 0; j < n; j++) {
        if (num == result[j]) {
          flag = false;
          break;
        }
      }
      if (flag) {
        result[count] = num;
        count++;
      }
    }
    return result;
  }

  //打开页面随机显示纸牌
  var shuzi = randomCommon(1, 14, 13);
  function showDifferent () {
    var cards = document.querySelectorAll('.out ul li');
    for (var i = 0; i < cards.length; i++) {
      
      cards[i].firstElementChild.src = "imgs/" + shuzi[i] + ".jpg";
    }
  }
  showDifferent();
  //显示结束




  
  /*
    拖放
  */
  function drag1 (ev) {
    var dataTrans = ev.dataTransfer;
  }
}